package com.wstro.task;

import com.wstro.entity.MaterialEntity;
import com.wstro.model.WechatTokenModel;
import com.wstro.service.MaterialService;
import com.wstro.service.WechatTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 测试定时任务(fixedRate在项目启动时会启动，cron不会启动)
 *
 * @author Joey
 * @Email 2434387555@qq.com
 */
@Component // 此注解必加
@EnableScheduling // 此注解必加
public class TestTask {

    private static final Logger logger = LoggerFactory.getLogger(TestTask.class);
    @Autowired
    private WechatTaskService wechatTaskService;
    @Autowired
    private MaterialService materialService;

    @Scheduled(fixedRate = 3600000) // 每1小时执行一次
    public void task() {
       // WechatTokenModel tokenModel = wechatTaskService.getWechatToken("wx480f55ca74e37a0d", "0cbb5975d73c5cfdb9981f23976f1bc5");
       //List<MaterialEntity> lists = wechatTaskService.getMaterial(tokenModel.getAccess_token(), "news", 0, 1000);
       //materialService.insertBatch(lists);
        logger.info("测试定时任务!");
    }

    //@Scheduled(cron = "0/100 * * * * ?") // 每2秒执行一次
    public void doSomething() throws Exception {
        logger.info("每2秒执行一个的定时任务：" + new Date());
    }

}
